/**
 * 
 */
package co.gov.medellin.sdep.sisdep.cco.service;

import java.util.Date;
import java.util.List;

import co.gov.medellin.sdep.sisdep.cco.exception.CentroComercialException;
import co.gov.medellin.sdep.sisdep.cco.exception.CentroComercialRuntimeException;
import co.gov.medellin.sdep.sisdep.cco.exception.SolicitudLocalCambioException;
import co.gov.medellin.sdep.sisdep.cco.exception.SolicitudLocalRuntimeException;
import co.gov.medellin.sdep.sisdep.cco.exception.descriptor.CentroComercialMessageDescriptor;
import co.gov.medellin.sdep.sisdep.cco.exception.descriptor.SolicitudLocalMessageDescriptor;
import co.gov.medellin.sdep.sisdep.common.message.MessageDescriptorConstant;
import co.gov.medellin.sdep.sisdep.common.service.BaseService;
import co.gov.medellin.sdep.sisdep.gestion.dto.VisitaAdministrativaDTO;
import co.gov.medellin.sdep.sisdep.gestion.exception.VisitaAdministrativaException;
import co.gov.medellin.sdep.sisdep.gestion.exception.VisitaAdministrativaRuntimeException;
import co.gov.medellin.sdep.sisdep.gestion.exception.descriptor.VisitaAdministrativaMessageDescriptor;
import co.gov.medellin.sdep.sisdep.model.CentroComercial;
import co.gov.medellin.sdep.sisdep.model.VisitaAdministrativa;
import co.gov.medellin.sdep.sisdep.model.dao.impl.ICentroComercialDAOT;

/**
 * @author Usuario
 *
 */
public class CentroComercialServiceImpl extends BaseService implements ICentroComercialService {

	//----------------------------------------------------------------------
	//--- propiedades y constructores                                 init()
	//----------------------------------------------------------------------

	/**
	 * default serial version
	 */
	private static final long serialVersionUID = 1L;
	/** */
	private ICentroComercialDAOT centroComercialDAO;

	/**
	 * 
	 */
	public CentroComercialServiceImpl() {
	}

	//----------------------------------------------------------------------
	//--- propiedades y constructores                                  end()
	//----------------------------------------------------------------------

	//----------------------------------------------------------------------
	//--- implementacion de metodos para acciones                     init()
	//----------------------------------------------------------------------

	/**
	 * 
	 */
	public void insert(CentroComercial centroComercial) throws CentroComercialException {
		try{
			centroComercial.setUsuarioCrea(getPrincipalUser());
			centroComercial.setFechaCrea(new Date());
			getCentroComercialDAO().insert(centroComercial);
		}catch (Exception e) {
			Object [] infoError = {
				centroComercial.getCodigo()
			};
			if(e.getCause().toString().indexOf("UNIQUE KEY") >= 0){
				throw new CentroComercialException(new CentroComercialMessageDescriptor(MessageDescriptorConstant.UK_VIOLATION), infoError, e);
			}else{
				throw new CentroComercialException(new CentroComercialMessageDescriptor(MessageDescriptorConstant.SAVE), infoError, e);
			}
		}
	}

	/**
	 * 
	 */
	public final void update(CentroComercial centroComercial) throws CentroComercialException {
		try{
			centroComercial.setUsuarioModifica(getPrincipalUser());
			centroComercial.setFechaModifica(new Date());
			getCentroComercialDAO().update(centroComercial);
		}catch (Exception e) {
			Object [] infoError = {
				centroComercial.getCodigo()
			};
			if(e.getCause().toString().indexOf("UNIQUE KEY") >= 0){
				throw new CentroComercialRuntimeException(new CentroComercialMessageDescriptor(MessageDescriptorConstant.UK_VIOLATION), infoError, e);
			}else{
				throw new CentroComercialRuntimeException(new CentroComercialMessageDescriptor(MessageDescriptorConstant.UPDATE), infoError, e);
			}
		}
	}

	/**
	 * 
	 */
	public final void delete(CentroComercial centroComercial) throws CentroComercialException {
		try {
			centroComercial.setUsuarioModifica(getPrincipalUser());
			centroComercial.setFechaModifica(new Date());
			getCentroComercialDAO().delete(centroComercial);
		}catch (Exception e) {
			Object [] infoError = {
				centroComercial.getCodigo()
			};
			throw new CentroComercialRuntimeException(new CentroComercialMessageDescriptor(MessageDescriptorConstant.DELETE), infoError, e);
		}
	}

	/**
	 * @return 
	 * 
	 */
	public final List load(int start,int max, CentroComercial centroComercial) throws CentroComercialException {
		try{
			//return getCentroComercialDAO().getAllCentroComercialPaginated(start, max, criteria);
			return getCentroComercialDAO().load();
		}catch (Exception e) {
			Object [] infoError = null;
			throw new CentroComercialRuntimeException(new CentroComercialMessageDescriptor(MessageDescriptorConstant.RETRIEVE), infoError, e);
		}
	}

	/**
	 * @return 
	 * 
	 */
	public final List loadByNombre(int start,int max, CentroComercial centroComercial) throws CentroComercialException {
		try{
			//return getCentroComercialDAO().getAllCentroComercialPaginated(start, max, criteria);
			return getCentroComercialDAO().loadByNombre(centroComercial);
		}catch (Exception e) {
			Object [] infoError = null;
			throw new CentroComercialRuntimeException(new CentroComercialMessageDescriptor(MessageDescriptorConstant.RETRIEVE), infoError, e);
		}
	}

	
	/**
	 * 
	 */
	public final CentroComercial get(long id) throws CentroComercialException {
		try{
			return getCentroComercialDAO().findByPrimaryKey(id);
		}catch (Exception e) {
			Object [] infoError = {new Long(id)};
			throw new CentroComercialRuntimeException(new CentroComercialMessageDescriptor(MessageDescriptorConstant.GET), infoError, e);
		}
	}
	
	/**
	 * @return 
	 * 
	 */
	public final List listaCentrosComerciales() throws CentroComercialException {
		try{
			//return getSolicitudLocalDAO().getAllSolicitudLocalPaginated(start, max, criteria);
			return getCentroComercialDAO().listaCentrosComerciales();
		}catch (Exception e) {
			Object [] infoError = null;
			throw new CentroComercialRuntimeException(new CentroComercialMessageDescriptor(MessageDescriptorConstant.RETRIEVE), infoError, e);
		}
	}
	
	public List generateXlsReportNumLocalesPorCCO() throws CentroComercialException {
		try{
			return getCentroComercialDAO().generateXlsReportNumLocalesPorCCO();
		} catch (Exception e) {
			Object [] infoError = null;
			
			throw new CentroComercialRuntimeException(
					new CentroComercialMessageDescriptor(MessageDescriptorConstant.RETRIEVE), infoError, e);
		}
	}	
	
	public List generateXlsReportNumLocalesDisponiblesPorCCO() throws CentroComercialException {
		try{
			return getCentroComercialDAO().generateXlsReportNumLocalesDisponiblesPorCCO();
		} catch (Exception e) {
			Object [] infoError = null;
			
			throw new CentroComercialRuntimeException(
					new CentroComercialMessageDescriptor(MessageDescriptorConstant.RETRIEVE), infoError, e);
		}
	}
	
	public List generateXlsReportLocalesPersonaPorCCO() throws CentroComercialException {
		try{
			return getCentroComercialDAO().generateXlsReportLocalesPersonaPorCCO();
		} catch (Exception e) {
			Object [] infoError = null;
			
			throw new CentroComercialRuntimeException(
					new CentroComercialMessageDescriptor(MessageDescriptorConstant.RETRIEVE), infoError, e);
		}
	}	
	
	public List generateXlsReportLocalesDisponiblesPorCCO() throws CentroComercialException {
		try{
			return getCentroComercialDAO().generateXlsReportLocalesDisponiblesPorCCO();
		} catch (Exception e) {
			Object [] infoError = null;
			
			throw new CentroComercialRuntimeException(
					new CentroComercialMessageDescriptor(MessageDescriptorConstant.RETRIEVE), infoError, e);
		}
	}	
	//----------------------------------------------------------------------
	//--- implementacion de metodos para acciones                      end()
	//----------------------------------------------------------------------

	//----------------------------------------------------------------------
	//--- getters and setters                                         init()
	//----------------------------------------------------------------------

	/**
	 * @author Usuario
	 *
	 */
	public ICentroComercialDAOT getCentroComercialDAO() {
		return centroComercialDAO;
	}

	/**
	 * @author Usuario
	 *
	 */
	public void setCentroComercialDAO(ICentroComercialDAOT centroComercialDAO) {
		this.centroComercialDAO = centroComercialDAO;
	}

	//----------------------------------------------------------------------
	//--- getters and setters                                          end()
	//----------------------------------------------------------------------

}
